package com.etrans.web.gps.business.command.controller;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etrans.web.gps.base.controller.BaseController;
import com.etrans.web.gps.business.command.service.CommandService;
import com.etrans.web.gps.business.gis.service.MonitorService;
import com.etrans.web.gps.business.system.domain.SysUser;
import com.etrans.web.gps.common.Constant;
@Controller
@RequestMapping("/cmd/command")
public class CommandController extends BaseController{
	private static final Logger logger = LoggerFactory.getLogger(CommandController.class);
	@Autowired
    private CommandService commandService;
	
	/**
	 * 发送指令
	 * @param vehicleId
	 * @param terminalId
	 * @param terminalType
	 * @param commno
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("sendCommand.html")
	@ResponseBody
	public Map<String,Object> sendCommand(String vehicleId,String terminalId,String terminalType,String commno,String commandId,String cmdArgs,String commandType) throws Exception{
		Map<String,Object> resultMap = new HashMap<>();
		Map<String,Object> params = new HashMap<>();
		SysUser user = (SysUser)getSession().getAttribute(Constant.LOGIN_SESSION_NAME);
		params.put("vehicleId", vehicleId);
		params.put("terminalId", terminalId);
		params.put("terminalType", terminalType);
		params.put("commno", commno);
		params.put("userId", user.getId());
		params.put("commandId", commandId);
		params.put("cmdArgs", cmdArgs);
		params.put("commandType",commandType);
		
		String _req_uuid = UUID.randomUUID().toString();
		long _req_time = System.currentTimeMillis();
		
//		UReqObj reqObj = new UReqObj(_req_uuid, _req_time, _user_id, _vehicle_id, _plate_num, _plate_color, _cmd_id, _cmd_args);
//		resultMap=commandService.sendCommand(params);
		return resultMap;
	}
	
	
	@RequestMapping("getCommandReply.html")
	@ResponseBody
	public Map<String,Object> getCommandReply(String terminaltype,String commno,String commandId,String cmdPkgSeq,String terminalId,String commandTime,String uuid) throws Exception{
		Map<String,Object> resultMap = new HashMap<>();
		Map<String,Object> params = new HashMap<>();
		params.put("terminaltype", terminaltype);
		params.put("commno", commno);
		params.put("commandId", commandId);
		params.put("cmdPkgSeq", cmdPkgSeq);
		params.put("terminalId", terminalId);
		params.put("commandTime", commandTime);
		params.put("uuid", uuid);
		resultMap=commandService.getCommandReply(params);	
		return resultMap;
	}
	
}
